import customApi from '@/api/declaration/crm/customApi'
import httpRequest from '@/config/axios/httpRequest'
import { CrmTransferReqModel } from '@/models/crm/CrmTransferReqModel'
import { CustomerModel } from '@/models/erp/CustomerModel'



// 查询客户列表
export const getCustomerPage = async (params) => {
  return await httpRequest.get(customApi.GetCustomerPage, { params })
}

// 进入公海客户提醒的客户列表
export const getPutPoolRemindCustomerPage = async (params) => {
  return await httpRequest.get(customApi.GetPutPoolRemindCustomerPage, { params })
}

// 获得待进入公海客户数量
export const getPutPoolRemindCustomerCount = async () => {
  return await httpRequest.get(customApi.GetPutPoolRemindCustomerCount)
}

// 获得今日需联系客户数量
export const getTodayContactCustomerCount = async () => {
  return await httpRequest.get(customApi.GetTodayContactCustomerCount)
}

// 获得分配给我、待跟进的线索数量的客户数量
export const getFollowCustomerCount = async () => {
  return await httpRequest.get(customApi.GetFollowCustomerCount)
}

// 查询客户详情
export const getCustomer = async (id: number) => {
  return await httpRequest.get(customApi.GetCustomer, { params: { id } })
}

// 新增客户
export const createCustomer = async (data: CustomerModel) => {
  return await httpRequest.post(customApi.CreateCustomer, data)
}

// 修改客户
export const updateCustomer = async (data: CustomerModel) => {
  return await httpRequest.put(customApi.UpdateCustomer, data)
}

// 更新客户的成交状态
export const updateCustomerDealStatus = async (id: number, dealStatus: boolean) => {
  return await httpRequest.put(customApi.UpdateCustomerDealStatus, { id, dealStatus })
}

// 删除客户
export const deleteCustomer = async (id: number) => {
  return await httpRequest.delete(customApi.DeleteCustomer, { params: { id } })
}

// 导出客户 Excel
export const exportCustomer = async (params: any) => {
  return await httpRequest.download(customApi.ExportCustomer, params)
}

// 下载客户导入模板
export const importCustomerTemplate = () => {
  return httpRequest.download(customApi.ImportCustomerTemplate)
}

// 导入客户
export const handleImport = async (formData) => {
  return await httpRequest.post(customApi.ImportCustomer, formData)
}

// 客户列表
export const getCustomerSimpleList = async () => {
  return await httpRequest.get(customApi.GetCustomerSimpleList)
}

// ======================= 业务操作 =======================

// 客户转移
export const transferCustomer = async (data: CrmTransferReqModel) => {
  return await httpRequest.put(customApi.TransferCustomer, data)
}

// 锁定/解锁客户
export const lockCustomer = async (id: number, lockStatus: boolean) => {
  return await httpRequest.put(customApi.LockCustomer, { id, lockStatus })
}

// 领取公海客户
export const receiveCustomer = async (ids: any[]) => {
  return await httpRequest.put(customApi.ReceivePublicSeaCustomer, { ids })
}

// 分配公海给对应负责人
export const distributeCustomer = async (ids: any[], ownerUserId: number) => {
  return await httpRequest.put(customApi.DistributionPublicSeaCustomer, { ids, ownerUserId })
}

// 客户放入公海
export const putCustomerPool = async (id: number) => {
  return await httpRequest.put(customApi.PutInPublicSeaCustomer, { id })
}
